

#include <stdint.h>
#include <string.h>

int SEGGER_RTT_GetKey(void);
unsigned SEGGER_RTT_Read(unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
unsigned SEGGER_RTT_Write(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);


/*********************************************************************/


int test_io_getc(void)
{
	return SEGGER_RTT_GetKey();
}

int test_io_wait_char(void)
{
	int c;
	while((c = SEGGER_RTT_GetKey()) < 0){
		// taskYIELD();
	}
	return c;
}

int test_io_gets(char *buf, int len)
{
	return SEGGER_RTT_Read(0, buf, len);
}

int test_io_wait_line(char *buf, int size){
	int i = 0;
	while(i < size){
		int c = test_io_wait_char();
		if(c == '\r'){
			continue;
		}
		if(c == '\n'){
			break;
		}
		buf[i++] = c;
	}
	buf[i] = 0;
	return i;
}

int test_io_puts(char *buf)
{
	return SEGGER_RTT_Write(0, buf, strlen(buf));
}